const { defineConfig } = require('@vue/cli-service')
// 打包优化
const cdn = {
  externals: {
    vue: 'Vue',
    axios: 'axios',
    'vue-router': 'VueRouter',
    'element-ui': 'ElementUI',
    echarts:'echarts'
  },
  js: [
    'https://cdn.bootcdn.net/ajax/libs/axios/1.3.4/axios.js',
    'https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js',
    'https://unpkg.com/vue-router@3.5.1/dist/vue-router.js',
    'https://unpkg.com/element-ui/lib/index.js',
    'https://cdn.bootcdn.net/ajax/libs/echarts/5.4.1/echarts.common.js'
  ]
}

module.exports = defineConfig({
  transpileDependencies: true,
  publicPath: './',
  configureWebpack: {
    externals: cdn.externals,
  },
  chainWebpack: (config) => {
    if (process.env.NODE_ENV === 'production') {
      config.plugin('html').tap(args => {
        args[0].cdn = cdn
        return args
      })
    }
    // config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  }
})
